﻿-- =============================================
-- Author:		Sandy Stewart, Fujitsu
-- Create date: 02/07/2011
-- Description:	Update command for ParliamentarianLinks entity
-- =============================================
CREATE PROCEDURE [dbo].[UpdateParliamentarianLink] 
	-- Add the parameters for the stored procedure here
	@CPALId int,
	@PartyWebsite varchar(100),
	@PersonalWebsite varchar(100),
	@FacebookAddress varchar(100),
	@TwitterAddress varchar(100)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF (SELECT COUNT(*) FROM ParliamentarianWebLinks WHERE CPALId = @CPALId) = 0
		BEGIN
			INSERT INTO ParliamentarianWebLinks
				(CPALId, PartyWebsite, PersonalWebsite, FacebookAddress, TwitterAddress)
			VALUES
				(@CPALId, @PartyWebsite, @PersonalWebsite, @FacebookAddress, @TwitterAddress)
		END
	ELSE
		BEGIN
			-- Update ParliamentarianWebLinks table
			UPDATE ParliamentarianWebLinks
			SET PartyWebsite = @PartyWebsite,
				PersonalWebsite = @PersonalWebsite,
				FacebookAddress = @FacebookAddress,
				TwitterAddress = @TwitterAddress
			WHERE CPALId = @CPALId
		END		

END